home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / mesa / mesa-glut / glue / start.in < prev   
Text File  |  2000-02-23  |  9KB  |  271 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #define START
  22. #include "../include/library_gl@TARGET@.h"
  23. #include "../include/version_gl@TARGET@.h"
  24.  
  25. /* size of C_PRIVATE was generated by create_header.c */
  26. /* include the generated header */
  27. #include "../start/start_gl@TARGET@.h"
  28.  
  29.  
  30.     .text
  31.  
  32.    | The first executable location.  This should return an error
  33.    | in case someone tried to run you as a program (instead of
  34.    | loading you as a library).
  35.     .globl    Start        | we use this to force inclusion of start.s
  36. Start:
  37.    movel   #-1,d0
  38.    rts
  39.  
  40. |-----------------------------------------------------------------------
  41. | A romtag structure.  Both "exec" and "ramlib" look for
  42. | this structure to discover magic constants about you
  43. | (such as where to start running you from...).
  44. |-----------------------------------------------------------------------
  45.  
  46. initDDescrip:
  47.                |STRUCTURE RT,0
  48.      .word    RTC_MATCHWORD           | UWORD RT_MATCHWORD
  49.      .long    initDDescrip            | APTR  RT_MATCHTAG
  50.      .long    EndCode                 | APTR  RT_ENDSKIP
  51.      .byte    RTF_AUTOINIT            | UBYTE RT_FLAGS
  52.      .byte    MesaGL@TARGET@_VERSION  | UBYTE RT_VERSION
  53.      .byte    NT_LIBRARY              | UBYTE RT_TYPE
  54.      .byte    MesaGL@TARGET@_PRIORITY | BYTE  RT_PRI
  55.      .long    name@TARGET@     | APTR  RT_NAME
  56.      .long    idString@TARGET@ | APTR  RT_IDSTRING
  57.      .long    Init                    | APTR  RT_INIT
  58.  
  59. | this is just fool proof, and this library will never make it to ROM
  60. | anyway, so resident tags are not that important ;-)
  61. EndCode:
  62.  
  63.  
  64.    | this is the name that the library will have
  65. name@TARGET@:    .asciz MesaGL@TARGET@_NAME
  66.  
  67.    | this is an identifier tag to help in supporting the library
  68.    | format is name version.revision (dd.mm.yy),<cr>,<lf>,<null>
  69.    | without any leading zeros in dd.mm.yy
  70. idString@TARGET@:
  71.     .ascii MesaGL@TARGET@_IDSTRING
  72.     .byte 13
  73.     .byte 10
  74.     .byte 0
  75.  
  76.    | force word alignment
  77.    .even
  78.  
  79.    | The romtag specified that we were "RTF_AUTOINIT".  This means
  80.    | that the RT_INIT structure member points to one of these
  81.    | tables below.  If the AUTOINIT bit was not set then RT_INIT
  82.    | would point to a routine to run.
  83.  
  84. Init:
  85.    .long   MesaGL@TARGET@BASE_SIZEOF    | size of library base data space
  86.    .long   funcTable        | pointer to function initializers
  87.    .long   dataTable            | pointer to data initializers
  88.    .long   _initRoutine            | routine to run
  89.  
  90.  
  91. funcTable:
  92.  
  93.    |------ standard system routines
  94.    .long   _libOpen
  95.    .long   _libClose
  96.    .long   _libExpunge
  97.    .long   Null
  98.  
  99.    |------ my libraries definitions
  100.  
  101. #define __reserved    Null
  102.  
  103. #define SYSTEM_CALL(func, vec) .long _##func
  104. #include "../include/GL/gl@TARGET@_calls.def"
  105. #undef SYSTEM_CALL
  106.  
  107.    |------ function table end marker
  108.    .long   -1
  109.  
  110.    | The data table initializes static data structures.
  111.    | The format is specified in exec/InitStruct routines
  112.    | manual pages.  The INITBYTE/INITWORD/INITLONG routines
  113.    | are in the file "exec/initializers.i".  The first argument
  114.    | is the offset from the library base for this byte/word/long.
  115.    | The second argument is the value to put in that cell.
  116.    | The table is null terminated
  117.    | NOTE - LN_TYPE below is a correction - old example had LH_TYPE
  118.  
  119. dataTable:
  120.     INITBYTE (LN_TYPE,                 NT_LIBRARY)
  121.     INITLONG (LN_NAME,                 name@TARGET@)
  122.     INITBYTE (MesaGL@TARGET@BASE_FLAGS,     0x6) | LIBF_CHANGED_SUMUSED
  123.     INITWORD (MesaGL@TARGET@BASE_VERSION,     MesaGL@TARGET@_VERSION)
  124.     INITWORD (MesaGL@TARGET@BASE_REVISION,     MesaGL@TARGET@_REVISION)
  125.     INITLONG (MesaGL@TARGET@BASE_IDSTRING,     idString@TARGET@)
  126.     .long   0
  127.  
  128.    | This routine gets called after the library has been allocated.
  129.    | The library pointer is in D0.  The segment list is in A0.
  130.    | If it returns non-zero then the library will be linked into
  131.    | the library list.
  132.  
  133. _initRoutine:
  134.    |------ get the library pointer into a convenient A register
  135.    movel   a5,sp@-
  136.    movel   d0,a5
  137.  
  138.    |------ save a pointer to our loaded code
  139.    movel   a0,a5@(MesaGL@TARGET@BASE_SEGLIST)
  140.  
  141.    |------ do the higher-level initialization in C
  142.    |------ the MesaGL@TARGET@init function checks if the hardware is supported
  143.    |------ (using 68000 instructions only) and if so will call MesaGL@TARGET@init()
  144.    |------ for the main initialization.
  145. |  pea       a5@
  146. |  jsr       _MesaGL@TARGET@init
  147. |  addqw   #4,sp
  148.  
  149.    movel   sp@+,a5
  150.    rts
  151.  
  152. |----------------------------------------------------------------------
  153. |
  154. | here begins the system interface commands.  When the user calls
  155. | OpenLibrary/CloseLibrary/RemoveLibrary, this eventually gets translated
  156. | into a call to the following routines (Open/Close/Expunge).  Exec
  157. | has already put our library pointer in A6 for us.  Exec has turned
  158. | off task switching while in these routines (via Forbid/Permit), so
  159. | we should not take too long in them.
  160. |
  161. |----------------------------------------------------------------------
  162.  
  163.  
  164.    | Open returns the library pointer in d0 if the open
  165.    | was successful.  If the open failed then null is returned.
  166.    | It might fail if we allocated memory on each open, or
  167.    | if only open application could have the library open
  168.    | at a time...
  169.  
  170. _libOpen:      | ( libptr:a6, version:d0 )
  171.    |------ mark us as having another opener
  172.    addqw   #1,a6@(MesaGL@TARGET@BASE_OPENCNT)
  173.  
  174.    |------ prevent delayed expunges
  175.    | !!!!!!
  176.    | commo - example code uses private flags field (MesaGL@TARGET@BASE_MYFLAGS), WHY????
  177.    | !!!!!!
  178.    bclr    #LIBB_DELEXP,a6@(MesaGL@TARGET@BASE_FLAGS)
  179.  
  180.    |------ do other things in C
  181. |  pea       a6@
  182. |  jsr       _MesaGL@TARGET@open
  183. |  addqw   #4,sp
  184. |  beq     OpenFailed
  185.    |--- MesaGL@TARGET@open() should return the library base, if all ok
  186.  
  187.    rts
  188.  
  189. OpenFailed:
  190.    subqw  #1,a6@(MesaGL@TARGET@BASE_OPENCNT)
  191.    rts
  192.  
  193.    | There are two different things that might be returned from
  194.    | the Close routine.  If the library is no longer open and
  195.    | there is a delayed expunge then Close should return the
  196.    | segment list (as given to Init).  Otherwise close should
  197.    | return NULL.
  198.  
  199. _libClose:      | ( libptr:a6 )
  200.    |------ do any cleanups needed in C
  201. |  pea       a6@
  202. |  jsr       _MesaGL@TARGET@close
  203. |  addqw   #4,sp
  204.  
  205.    |------ mark us as having one fewer openers
  206.    subqw   #1,a6@(MesaGL@TARGET@BASE_OPENCNT)
  207.  
  208.    |------ see if there is anyone left with us open
  209.    bne     Null
  210.  
  211.    |------ see if we have a delayed expunge pending
  212.    btst    #LIBB_DELEXP,a6@(MesaGL@TARGET@BASE_FLAGS)    | SEE ABOVE!
  213.    bne     _libExpunge
  214.  
  215.    | reserved entry
  216.  
  217. Null:
  218.    moveq   #0,d0
  219.    rts
  220.  
  221.    | There are two different things that might be returned from
  222.    | the Expunge routine.  If the library is no longer open
  223.    | then Expunge should return the segment list (as given to
  224.    | Init).  Otherwise Expunge should set the delayed expunge
  225.    | flag and return NULL.
  226.    |
  227.    | One other important note: because Expunge is called from
  228.    | the memory allocator, it may NEVER Wait() or otherwise
  229.    | take long time to complete.
  230.  
  231. _libExpunge:   | ( libptr: a6 )
  232.    moveml  a2/a5/a6,sp@-
  233.    movel   a6,a5
  234.  
  235.    |------ assume we cant expunge
  236.    subal   a2,a2
  237.    bset    #LIBB_DELEXP,a5@(MesaGL@TARGET@BASE_FLAGS)    | SEE ABOVE !!
  238.  
  239.    |------ see if anyone has us open
  240.    tstw    a5@(MesaGL@TARGET@BASE_OPENCNT)
  241.    bne     L21
  242.  
  243.    |------ go ahead and get rid of us.  Store our seglist in a2
  244.    movel   a5@(MesaGL@TARGET@BASE_SEGLIST),a2
  245.    movel   4:w,a6
  246.  
  247.    |------ unlink from library list
  248.    movel   a5,a1
  249.    jsr       a6@(_LVORemove)
  250.  
  251.    |
  252.    | device specific closings here...
  253.    |
  254. |  pea       a5@
  255. |  jsr       _MesaGL@TARGET@expunge
  256. |  addqw   #4,sp
  257.  
  258.    |------ free our memory
  259.    movel   a5,a1
  260.    moveq   #0,d0
  261.    movew   a5@(MesaGL@TARGET@BASE_NEGSIZE),d0
  262.    subl    d0,a1
  263.    addw    a5@(MesaGL@TARGET@BASE_POSSIZE),d0
  264.    jsr       a6@(_LVOFreeMem)
  265.  
  266. L21:       |------ set up our return value
  267.    movel   a2,d0
  268.  
  269.    moveml  sp@+,a2/a5/a6
  270.    rts
  271.